 // 判断输入的是不是字母



$("#primaryKeys").bind('input porpertychange',function(){
	var reg = /^[A-Za-z]+$/;
	var val = $('#primaryKeys').val()
	console.log("e");
	if (reg.test(val)) { 
		$('#primaryKeys').css("border","1px solid #e2e2e2")
	}else{
		$('#primaryKeys').css("border","1px solid red")
		layer.msg("只能输入字母", {
			time : 2000
		//2s后自动关闭
		});
		return false;
	}
	});

function generatorCode(){
	    var d = {};
	    var t = $('form').serializeArray();
	    $.each(t, function() {
	      d[this.name] = this.value;
	    });
	    if(d.dbUrlId==""||d.dbName==""||d.models==""||d.projectNames==""||d.tableNames==""||d.companyNames==""||d.authors==""||d.objectNameCns==""||d.objectNames==""||d.abbObjectNames==""){
	    	
	    }else{
	    	var index = layer.load(0, {shade: false});
		    $.ajax({
				type : 'POST',
				dataType : 'JSON',
				url :  basePath+'/code/codeGenator.jhtml',
				data :d,
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					layer.msg('系统错误！！', {
						time : 2000
					//2s后自动关闭
					});
				},
				success : function(rs) {
					var code = rs.code;
					if (code == 1) {
						var url = basePath+'/code/downZip.jhtml?zipName='+rs.data;
						location.href=url;
						layer.close(index)
						layer.msg(rs.msg, {
							time : 4000,
							offset: 't',
							icon: 6
						//2s后自动关闭
						});
						return false
					} else {
						layer.close(index)
						layer.msg(rs.msg, {
							time : 4000,
							offset: 't',
							icon: 7
						//2s后自动关闭
						});
						return false
					}
	
				} 
			});
	    }
}


layui.use(['element','form','layer','laydate'], function(){
 var element = layui.element;
 var form = layui.form;
  form.render();
  /* form.on('submit(formDemo)', function(data){
	    	$.ajax({
				type : 'POST',
				dataType : 'JSON',
				url :  basePath+'/code/codeGenator.jhtml',
				data :data.field,
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					layer.msg('系统错误！！', {
						time : 2000
					//2s后自动关闭
					});
				},
				success : function(data) {
					var code = data.code;
					if (code == '100') {
						layer.msg(data.message, {
							time : 2000
						//2s后自动关闭
						});
					} else {
						layer.msg(data.message, {
							time : 2000
						//2s后自动关闭
						});
					}

				}
			});
	  
  });*/
  
  form.on('select(serviceFilter)', function(formData){
	  var index = layer.load(0, {
		  shade: [0.2,'#000'] //0.1透明度的白色背景
		});
  	  $.getJSON(tdmPath+"/code/getDataBaseByService.jhtml?dbUrlId="+formData.value, function(data){
           var optionstring = "";
           if(data.code==1){
        	   
              	 $.each(data.data, function(i,item){
              		 optionstring += "<option value=\"" + item + "\" >" + item + "</option>";
              	  });
          		 $("#dbName").html(optionstring);
           form.render('select'); //重新渲染
          
           }else if(data.code==2){
        	  layer.msg(data.msg, {
					time : 2000
				//2s后自动关闭
				});
           }else{
        	   layer.msg(data.msg, {
					time : 2000
				//2s后自动关闭
				});
           }
       }); 
  	  layer.close(index);
  	});
  
});